﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;


namespace PicoInvokeWebSvc
{
    /// <summary>
    /// Summary description for PicoSvc
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class PicoSvc : System.Web.Services.WebService
    {

        [WebMethod]
        public bool UploadBitFile(string psTopComponent)
        {
            string sBitFilePath = Server.MapPath(".");
            string sCommand = "PicoCommand";
            string sParam = "/c " + psTopComponent.ToLower() + ".bit " + RapidHDL.TextFile.BuildFileName(sBitFilePath, psTopComponent.ToLower() + ".bit");
            RapidHDL.ShellControl.StartExe("c:\\pico\\bin\\" + sCommand, sBitFilePath, sParam);
            while (RapidHDL.ShellControl.GetProcessCount(sCommand) > 0)
            {
                System.Threading.Thread.Sleep(2000);
            }

            sParam = "/w " + RapidHDL.TextFile.BuildFileName(sBitFilePath, psTopComponent.ToLower() + ".bit");
            RapidHDL.ShellControl.StartExe("c:\\pico\\bin\\" + sCommand, sBitFilePath, sParam);
            while (RapidHDL.ShellControl.GetProcessCount(sCommand) > 0)
            {
                System.Threading.Thread.Sleep(1000);
            }

            return true;
        }
    }
}
